<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RAction
 *
 * @author Administrator
 */
import('@.Filter.SecurityAction');
import('@.Service.RecommendationService');
import('ORG.Util.Page');

class RAction extends SecurityAction {

    function r() {
        $r = new RecommendationService();
        $query = $_REQUEST['query'];
        $count;

        if ('r1' == $query) {
            $count = $r->countAll(null, 1);
        } elseif ('r0' == $query) {
            $count = $r->countAll(null, 0);
        } elseif ('c1' == $query) {
            $count = $r->countAll(1, null);
        } elseif ('c0' == $query) {
            $count = $r->countAll(0, null);
        } else {
            $count = $r->countAll();
        }

//dump(D('recommendation')->getLastSql());return;
        $page = new Page($count, 10);
        $map['query'] = $query;
        foreach ($map as $key => $val) {
            $page->parameter .= "$key=" . urlencode($val) . "&";
        }
        $show = $page->show();
        $list;
        if ('r1' == $query) {
            $list = $r->listAll($page->firstRow . ',' . $page->listRows, null, 1);
        } elseif ('r0' == $query) {
            $list = $r->listAll($page->firstRow . ',' . $page->listRows, null, 0);
        } elseif ('c1' == $query) {
            $list = $r->listAll($page->firstRow . ',' . $page->listRows, 1);
        } elseif ('c0' == $query) {
            $list = $r->listAll($page->firstRow . ',' . $page->listRows, 0);
        } else {
            $list = $r->listAll($page->firstRow . ',' . $page->listRows);
        }
//dump(D('recommendation')->getLastSql());

        $this->assign('list', $list);
        $this->assign('show', $show);

        $this->assign('content', 'r');
        $this->display('Admin:global');
    }

    function reply() {
        $r = new RecommendationService();

        $id = $_REQUEST['id'];
        if (empty($id)) {
            $this->error('');
            return;
        }
        $recomm = $r->findRById($id);

        if (empty($recomm)) {
            $this->error('');
            return;
        }

        $this->assign('r', $recomm);
        $this->assign('content', 'reply');
        $this->display('Admin:global');
    }

    function saveReply() {
        $r = new RecommendationService();

        $recomm = $r->create();
        if (empty($_REQUEST['is_add'])) {
            $recomm['is_add'] = 0;
        }
        $r->update($recomm);

        $this->redirect('r');
    }

}

?>
